package ai.leinao.notify.email;

import ai.leinao.notify.core.NotifyProperties;
import ai.leinao.notify.core.enums.NotifyType;
import ai.leinao.notify.core.provider.NotifierProvider;
import ai.leinao.notify.core.template.TemplateProperties;
import ai.leinao.notify.core.template.TemplateProvider;
import ai.leinao.notify.core.template.TemplateRegistry;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 邮箱通知方式供应商枚举
 *
 * @author zhong.wang
 * @date 2025/7/8
 */
@Component
@AllArgsConstructor
public class EmailNotifierProvider implements NotifierProvider, TemplateProvider {
    /**
     * 模板注册器
     */
    private final TemplateRegistry templateRegistry;

    /**
     * 获取通知类型
     *
     * @return 通知类型
     */
    @Override
    public NotifyType getNotifyType() {
        return NotifyType.EMAIL;
    }

    /**
     * 获取供应商名称
     *
     * @return
     */
    @Override
    public String getProvider() {
        return EmailProviderEnum.EMAIL.getType();
    }

    /**
     * 创建通知模板
     *
     * @param properties
     * @return
     */
    @Override
    public EmailTemplate createTemplate(TemplateProperties properties) {
        return new EmailTemplate().of(properties);
    }

    /**
     * 根据通知配置创建通知器
     *
     * @param properties
     * @return 通知器
     */
    @Override
    public EmailNotifier createNotifier(NotifyProperties properties) {
        EmailNotifier emailNotifier = new EmailNotifier(properties, templateRegistry);
        return emailNotifier;
    }

}
